const tmpl = `
namespace Yell.Domain.{{module}};

public class {{Domian}}Service : Service, I{{Domian}}Service
{
    private readonly IRepository<{{Domian}}> _{{domian}}Repo;

    public {{Domian}}Service(IRepository<{{Domian}}> {{domian}}Repo)
    {
        _{{domian}}Repo = {{domian}}Repo;
    }

    public async Task<PageList<{{Domian}}>> GetListAsync({{Domian}}SearchInput input)
    {
        return await _{{domian}}Repo
            .AsQueryable()
            .WhereIF(
                Utils.NotNull(input.Keyword), 
                s => s.Code.StartsWith(input.Keyword) || s.Name.StartsWith(input.Keyword))
            .WhereConds(input)
            .ToPageListAsync(input);
    }

    public Task<{{Domian}}> GetAsync(long id)
    {
        return _{{domian}}Repo.AsQueryable().FirstAsync(s => s.Id == id);
    }

    public async Task CreateAsync({{Domian}} {{domian}})
    {
        await _{{domian}}Repo.InsertAsync({{domian}});
    }

    public async Task UpdateAsync({{Domian}} {{domian}})
    {
        Utils.ThrowIfNull({{domian}}.Id, "主键不能为空！");
        await _{{domian}}Repo.UpdateAsync({{domian}});
    }

    public async Task DeleteAsync(params long[] ids)
    {
        await _{{domian}}Repo.DeleteByIdsAsync(ids);
    }

}

public class {{Domian}}SearchInput : PageSearch
{
    public string Keyword { get; set; }
}





namespace Yell.Domain.{{module}};

public interface I{{Domain}}Service
{
    Task<PageList<{{Domain}}>> GetListAsync(ProcessSearchInput input);
    Task<{{Domain}}> GetAsync(long id);
    Task CreateAsync({{Domain}} {{domain}});
    Task UpdateAsync({{Domain}} {{domain}});
    Task DeleteAsync(params long[] ids);

}
`

export function genServiceCode(domain: string, moduleName: string) {
  return tmpl.replaceAll('{{domian}}', domain)
    .replaceAll('{{Domian}}', domain.slice(0, 1).toUpperCase() + domain.slice(1))
    .replaceAll('{{module}}', moduleName)
}